<template>
   <view class="list_container">
         <up-list
                     @scrolltolower="scrolltolower"
                 >
                     <up-list-item
                         v-for="(item, index) in indexList"
                         :key="index"
                         :height="winHeight-106"
                     >
                   <OtherOffer v-bind="item"/>
                     </up-list-item>
                 </up-list>
     </view>

     
</template>

<script setup lang="ts">
import { useMemberStore } from '@/stores/models/menbers';
import { useCurrentServe } from '@/stores/models/server';
import { http } from '@/utils/http';
import type { OfferWinProps,  OhterOfferProps, ResOfferInfoData } from '@/utils/page_types';
import { onLoad } from '@dcloudio/uni-app';
import {ref,reactive, onBeforeMount, onMounted} from 'vue';

const isShowOfferWin = ref(false)
const indexList = ref<OhterOfferProps[]>([]);
const winProps = ref<OfferWinProps>({} as OfferWinProps)
const winHeight = ref();
const serverStore = useCurrentServe()
const currentPage = ref(1)

onLoad(()=>{
    winHeight.value=uni.getSystemInfoSync().windowHeight;
})

 onMounted(()=>{
  loadMore();
 })

const scrolltolower = () => {
  loadMore();
};

const loadMore=async ()=>{
    console.log("loadReceiveOffer",serverStore.serverId)
   const data=await http<Array<ResOfferInfoData>>({
		url:"/offerReceive",
		data:{
			type:1,
			page:currentPage.value,
			size:20,
			serverId:serverStore.serverId
		},
		method:"GET"
	 });
	 console.log("data",data)
	 const list =data.data;
     if(!list) return;
   
     for(let i=0;i<list.length;i++){
		let infoData= list[i];
		let obj:OhterOfferProps ={
            id:infoData.sdInfoId,
         title:infoData.title,
		 userName:infoData.openId,
		 updateTime:infoData.updateAt.toString(),
		 price:infoData.price.toString(),
		 num:infoData.num.toString(),
	     otherNum:infoData.offer_num.toString(),
         otherPrice:infoData.offer_price,
         offerId:infoData.offer_id,
         infoId:infoData.sdInfoId,
         dealUser:infoData.openId,
         offerUser:infoData.offer_user,
         status:infoData.status.toString(),
         initList:initList

	}
	indexList.value.push(obj)
	 }
	 currentPage.value++;
 }



 const initList=()=>{
    currentPage.value=1;
    indexList.value.length=0;
    loadMore();
 }





   
</script>

<style lang="scss">
   .list_container{
       display:flex;
       flex-direction: column;
       align-items: center;
   }
   page{
       background-color: #f6f6f6;
   }
   .tabview{
       width: 95%;
       margin: 0 auto;
       margin-top: 3px
   }
</style>
